//
//  MSLabel.swift
//  onemeetingmac
//
//  Created by 张衡 on 2020/7/1.
//  Copyright © 2020 onemeeting. All rights reserved.
//

import Foundation



class MSLabel: NSLabel {
    var tap:OneViewBlock?
    var mouse:OneStatusBlock?
    
    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect)
        let optios:NSTrackingArea.Options = [
            NSTrackingArea.Options.mouseEnteredAndExited,
            NSTrackingArea.Options.mouseMoved,
            NSTrackingArea.Options.cursorUpdate,
            NSTrackingArea.Options.activeWhenFirstResponder,
            NSTrackingArea.Options.activeInKeyWindow,
            NSTrackingArea.Options.activeInActiveApp,
            NSTrackingArea.Options.activeAlways,
            NSTrackingArea.Options.assumeInside,
            NSTrackingArea.Options.inVisibleRect,
            NSTrackingArea.Options.enabledDuringMouseDrag
        ]
       
        let area = NSTrackingArea.init(rect: dirtyRect, options: optios, owner: self, userInfo: nil)
        self.addTrackingArea(area)
        self.becomeFirstResponder()
    }
   
    override func mouseDown(with event: NSEvent) {
        super.mouseDown(with: event)
        if self.tap != nil {
            self.tap!(self)
        }
        if let mouseStatus = self.mouse {
            mouseStatus(.selected)
        }
    }
    
    override func mouseUp(with event: NSEvent) {
        super.mouseUp(with: event)
        if let mouseStatus = self.mouse {
            mouseStatus(.hover)
        }
    }
       
    override func mouseEntered(with event: NSEvent) {
        super.mouseEntered(with: event)
        if let mouseStatus = self.mouse {
            mouseStatus(.highlight)
        }
    }
       
    override func mouseExited(with event: NSEvent) {
        super.mouseExited(with:event)
        if let mouseStatus = self.mouse {
            mouseStatus(.normal)
        }
    }
    

    
}
